package cn.ffcs.uec.outStaffEntryApply.action;


import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Tab;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.raptornuke.portal.theme.ThemeDisplay;
import cn.ffcs.uec.outStaff.constant.UecOutStaffConstants;
import cn.ffcs.uec.outStaffEntryApply.action.bean.OutStaffEntryTabsApprovalViewMainBean;
import cn.ffcs.uec.staffRecords.vo.AtiOaBaseObject;

/**
 * 审批弹窗中查看人员tabs页信息的弹窗
 * 
 * @author liuxiaodong
 *
 */
@Controller
@Scope("prototype")
public class OutStaffEntryTabsApprovalViewMainComposer extends
		BasePortletComposer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3654114631138719292L;

	private OutStaffEntryTabsApprovalViewMainBean bean = new OutStaffEntryTabsApprovalViewMainBean();
	
	private AtiOaBaseObject atiOaBaseObject;
	
	private String taskDefKey;

	@Override
	public String getPortletId() {
		return super.getPortletId();
	}

	@Override
	public ThemeDisplay getThemeDisplay() {
		return super.getThemeDisplay();
	}

	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);

	}

	/**
	 * 界面初始化
	 */
	public void onCreate$outStaffEntryTabsApprovalViewMainWin() {
		setButtionUnvisible();
		bindBean();
		
		
	}
	
	public void bindBean() {
		atiOaBaseObject = (AtiOaBaseObject) arg.get("oaBaseObject");
		taskDefKey = (String) arg.get("taskDefKey");
		bean.getOutStaffEntryTabsApprovalViewMainWin().setTitle("外包人员入职审批信息查看");
		callTab();
		if ("modify".equals(taskDefKey)) {
			setEditButton();
		}
	}
	
	/**
	 * 审批驳回可以重新修改
	 */
	private void setEditButton() {
		bean.getUecOutDocEduListboxExt().getBean().getApprovalEditButton().setVisible(true);
		bean.getUecOutStaffEncListboxExt().getBean().getApprovalEditButton().setVisible(true);
		bean.getUecOutStaffFamilyListboxExt().getBean().getApprovalEditButton().setVisible(true);
		bean.getUecOutStaffNationdutyListboxExt().getBean().getApprovalEditButton().setVisible(true);
		bean.getUecOutStaffPartyLogListboxExt().getBean().getApprovalEditButton().setVisible(true);
		bean.getUecOutStaffPunishListboxExt().getBean().getApprovalEditButton().setVisible(true);
		bean.getUecOutStaffTitleListboxExt().getBean().getApprovalEditButton().setVisible(true);

	}
	
	/**
	 * tab响应
	 * 
	 * @throws Exception
	 * 
	 */
	public void callTab() {
		try {
			if (bean.getTab() == null) {
				bean.setTab(bean.getTabBox().getSelectedTab());
			}
			if (atiOaBaseObject != null) {
				String tab = this.bean.getTab().getId();
				if ("uecOutStaffDocEdu".equals(tab)) {
					Events.postEvent(
							UecOutStaffConstants.ON_UEC_OUT_DOC_EDU_QUERY_OF_OUTSTAFF_ENTRY_VIEW,
							bean.getUecOutDocEduListboxExt(), atiOaBaseObject.getEduId());
				} else if ("uecOutStaffFamily".equals(tab)) {
					Events.postEvent(
							UecOutStaffConstants.ON_UEC_OUT_STAFF_FAMILY_QUERY_OF_OUTSTAFF_ENTRY_VIEW,
							bean.getUecOutStaffFamilyListboxExt(), atiOaBaseObject.getFamilyId());
				} else if ("uecOutStaffTitle".equals(tab)) {
					Events.postEvent(
							UecOutStaffConstants.ON_UEC_OUT_STAFF_TITLE_QUERY_OF_OUTSTAFF_ENTRY_VIEW,
							bean.getUecOutStaffTitleListboxExt(), atiOaBaseObject.getTitleId());
				} else if ("uecOutStaffNationduty".equals(tab)) {
					Events.postEvent(
							UecOutStaffConstants.ON_UEC_OUT_STAFF_NATION_DUTY_QUERY_OF_OUTSTAFF_ENTRY_VIEW,
							bean.getUecOutStaffNationdutyListboxExt(), atiOaBaseObject.getNationdutyId());
				} else if ("uecOutStaffEnc".equals(tab)) {
					Events.postEvent(
							UecOutStaffConstants.ON_UEC_OUT_STAFF_ENC_QUERY_OF_OUTSTAFF_ENTRY_VIEW,
							bean.getUecOutStaffEncListboxExt(), atiOaBaseObject.getEncId());
				} else if ("uecOutStaffPunish".equals(tab)) {
					Events.postEvent(
							UecOutStaffConstants.ON_UEC_OUT_STAFF_PUNISH_QUERY_OF_OUTSTAFF_ENTRY_VIEW,
							bean.getUecOutStaffPunishListboxExt(), atiOaBaseObject.getPunishId());
				} else if ("uecOutStaffPartyLog".equals(tab)) {
					Events.postEvent(
							UecOutStaffConstants.ON_UEC_OUT_STAFF_PARTYLOG_QUERY_OF_OUTSTAFF_ENTRY_VIEW,
							bean.getUecOutStaffPartyLogListboxExt(), atiOaBaseObject.getPartyLogId());
				}
			} else {
				// 清空数据
				bean.getUecOutDocEduListboxExt().onCleanUecOutDocEduResponse(
						null);
				bean.getUecOutStaffEncListboxExt()
						.onCleanUecOutStaffEncResponse(null);
				bean.getUecOutStaffPunishListboxExt()
						.onUecOutStaffPunishQueryResponse(null);
				bean.getUecOutStaffPartyLogListboxExt()
						.onUecOutStaffPartyLogQueryResponse(null);
				bean.getUecOutStaffFamilyListboxExt()
						.onUecOutStaffFamilyQueryResponse(null);
				bean.getUecOutStaffNationdutyListboxExt()
						.onUecOutStaffNationdutyQueryResponse(null);
				bean.getUecOutStaffTitleListboxExt()
						.onUecOutStaffTitleQueryResponse(null);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void onClickTab(ForwardEvent event) {
		try {
			Event origin = event.getOrigin();
			if (origin != null) {
				Component comp = origin.getTarget();
				if (comp != null && comp instanceof Tab) {
					bean.setTab((Tab) comp);
					callTab();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	// 审批查看，隐藏按钮
	public void setButtionUnvisible() {
		bean.getUecOutDocEduListboxExt().getBean().getViewButton().setVisible(false);
		bean.getUecOutDocEduListboxExt().getBean().getAddButton().setVisible(false);
		bean.getUecOutDocEduListboxExt().getBean().getDelButton().setVisible(false);
		bean.getUecOutDocEduListboxExt().getBean().getEditButton().setVisible(false);
		
		bean.getUecOutStaffEncListboxExt().getBean().getAddButton().setVisible(false);
		bean.getUecOutStaffEncListboxExt().getBean().getDelButton().setVisible(false);
		bean.getUecOutStaffEncListboxExt().getBean().getDownloadButton().setVisible(false);
		bean.getUecOutStaffEncListboxExt().getBean().getEditButton().setVisible(false);
		bean.getUecOutStaffEncListboxExt().getBean().getUploadButton().setVisible(false);
		bean.getUecOutStaffEncListboxExt().getBean().getViewButton().setVisible(false);
		
		bean.getUecOutStaffFamilyListboxExt().getBean().getAddButton().setVisible(false);
		bean.getUecOutStaffFamilyListboxExt().getBean().getDelButton().setVisible(false);
		bean.getUecOutStaffFamilyListboxExt().getBean().getEditButton().setVisible(false);
		bean.getUecOutStaffFamilyListboxExt().getBean().getViewButton().setVisible(false);
		
		bean.getUecOutStaffNationdutyListboxExt().getBean().getAddButton().setVisible(false);
		bean.getUecOutStaffNationdutyListboxExt().getBean().getDelButton().setVisible(false);
		bean.getUecOutStaffNationdutyListboxExt().getBean().getEditButton().setVisible(false);
		bean.getUecOutStaffNationdutyListboxExt().getBean().getViewButton().setVisible(false);
		
		bean.getUecOutStaffPartyLogListboxExt().getBean().getAddButton().setVisible(false);
		bean.getUecOutStaffPartyLogListboxExt().getBean().getDelButton().setVisible(false);
		bean.getUecOutStaffPartyLogListboxExt().getBean().getEditButton().setVisible(false);
		bean.getUecOutStaffPartyLogListboxExt().getBean().getViewButton().setVisible(false);
		
		bean.getUecOutStaffPunishListboxExt().getBean().getAddButton().setVisible(false);
		bean.getUecOutStaffPunishListboxExt().getBean().getDelButton().setVisible(false);
		bean.getUecOutStaffPunishListboxExt().getBean().getDownloadButton().setVisible(false);
		bean.getUecOutStaffPunishListboxExt().getBean().getEditButton().setVisible(false);
		bean.getUecOutStaffPunishListboxExt().getBean().getUploadButton().setVisible(false);
		bean.getUecOutStaffPunishListboxExt().getBean().getViewButton().setVisible(false);
		
		bean.getUecOutStaffTitleListboxExt().getBean().getAddButton().setVisible(false);
		bean.getUecOutStaffTitleListboxExt().getBean().getDelButton().setVisible(false);
		bean.getUecOutStaffTitleListboxExt().getBean().getEditButton().setVisible(false);
		bean.getUecOutStaffTitleListboxExt().getBean().getViewButton().setVisible(false);
	}
	
	
	

}
